package com.triumphxx.datadeal;

import java.util.*;
import java.util.stream.Collectors;

public class FilterDemo {
    // 定义条件键值对（用于封装 a 和 b 的组合）
    static class ConditionKey {
        private final Object a;
        private final Object b;

        public ConditionKey(Object a, Object b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            ConditionKey that = (ConditionKey) o;
            return Objects.equals(a, that.a) && Objects.equals(b, that.b);
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }
    }

    // 核心过滤方法
    public static List<ObjectA> filterList(List<ObjectA> targetList, List<ObjectB> conditionList) {
        // 1. 构建条件集合（快速判断是否存在匹配条件）
        Set<ConditionKey> conditionSet = conditionList.stream()
                .map(objB -> new ConditionKey(objB.getA(), objB.getB()))
                .collect(Collectors.toSet());

        // 2. 过滤目标列表：保留不满足条件的 ObjectA
        return targetList.stream()
                .filter(objA -> conditionSet.contains(new ConditionKey(objA.getA(), objA.getB())))
                .collect(Collectors.toList());
    }

    // 测试示例
    public static void main(String[] args) {
        // 准备测试数据
        List<ObjectA> targetList = Arrays.asList(
                new ObjectA("a1", "b1"),
                new ObjectA("a2", "b2"),
                new ObjectA("a3", "b3")
        );

        List<ObjectB> conditionList = Arrays.asList(
                new ObjectB("a1", "b1"),  // 此条件将被剔除
                new ObjectB("a3", "b3")   // 此条件将被剔除
        );

        // 执行过滤
        List<ObjectA> result = filterList(targetList, conditionList);

        // 输出结果：[ObjectA(a2, b2)]
        System.out.println(result);
    }
}

// 示例类定义（实际使用时替换为您的类）
class ObjectA {
    private Object a;
    private Object b;

    public ObjectA(Object a, Object b) {
        this.a = a;
        this.b = b;
    }

    public Object getA() { return a; }
    public Object getB() { return b; }

    @Override
    public String toString() {
        return "ObjectA(" + a + ", " + b + ")";
    }
}

class ObjectB {
    private Object a;
    private Object b;

    public ObjectB(Object a, Object b) {
        this.a = a;
        this.b = b;
    }

    public Object getA() { return a; }
    public Object getB() { return b; }
}